<?php
session_start();
include("controller/auth.php");
require_once 'controller/config.inc';
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../favicon.png">
 <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/popover.js"></script>
    <script>
    $(function(){
    	$('a').tooltip({'placement':'right', 'trigger' : 'hover'});
    });
    </script>
    <title>Online Shopping</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">
	<link href="css/font-awesome.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="jumbotron.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html#">Kharidaree</a>
        </div>
        <div class="navbar-collapse collapse">
         
       
         <a href='logout.php' class='pull-right btn btn-danger'>Logout!</a>
         
       
        </div><!--/.navbar-collapse -->
      </div>
    </div>

    <!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
      <div class="container">
        <h1>Welcome: <?php echo $_SESSION['MN'] . " " . $_SESSION['ML'];?></h1>
        <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
        <p><a class="btn btn-primary btn-lg" role="button">Learn more &raquo;</a></p>
      </div>
    </div>

    <div class="container">
      <!-- Example row of columns -->
      <div class="row">
      
       <?php 
  if(isset($_GET['status'])){
  		if($_GET['status']==success){
  		echo "<div class='alert alert-success'>Item has been Delete!</div>";
  		}
  		else{
  			echo "<div class='alert alert-error'>Denied! You have no privileges to Delete this Item</div>";
  			
  		}
  }
  ?>
       <!-- Nav tabs -->
<ul class="nav nav-tabs" id='myTab'>
  <li><a href="#home" data-toggle="tab">Add Item</a></li>
  <li><a href="#profile" data-toggle="tab">Maintain Items</a></li>
  <li><a href="#messages" data-toggle="tab">Pricing</a></li>
  <li><a href="#settings" data-toggle="tab">Customer Management</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home">
	<div class='row'>
	
	<br/>
	<form class="form-inline" role="form" action='controller/upload_photo.php' method="post"
enctype="multipart/form-data">
  <div class="form-group">
    <label class="sr-only" for="exampleInputEmail2">Select Photo:</label>
    <input type="file" class="form-control" id="exampleInputEmail2" name='f_photo'>
  </div>
 
 
  <button type="submit" class="btn btn-primary">Upload Photo</button>
</form>


	<form class="form-horizontal" role="form" action='controller/addItem.php' method='POST'>
		<div class='col-md-6'>
			<br class='clearfix'/>
			
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Serial Number:</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="inputEmail3" name="sn">
    </div>
  </div>
   <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Name:</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="inputEmail3" name="nm">
    </div>
  </div>
   <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Category</label>
    <div class="col-sm-10">
      <select class="form-control" name='cat'>
      <option value=''>Select Category</option>
  <option value='Devices'>Devices</option>
  <option value='Wearables'>Wearables</option>
  <option value='Computers'>Computers</option>
  <option value='Books'>Books</option>
  <option value='Jewererly'>Jewererly</option>
</select>
    </div>
  </div>
   <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Size</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="inputEmail3" name='size'>
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Price</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name='price'>
    </div>
  </div>
  


		</div>
		
		<div class='col-md-6'>
		<br/>
		<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Manufacturer</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name='manf'>
    </div>
  </div>
   <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Status</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name='status'>
    </div>
  </div>
  <?php 
  if(isset($_GET['fn'])){
  		$file=$_GET['fn'];
  	
  }
  ?>
   <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Photo</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name='photo' value='<?php echo $file; ?>'>
    </div>
  </div>
  

			  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-primary">Add Item</button>
    </div>
  </div>
		</div>
		
		</form>
	
	</div>
</div>
<!-- /Add Item -->
  <div class="tab-pane" id="profile">
 <?php 
 $total_qry=mysql_query("SELECT * FROM items");
  		$count=mysql_num_rows($total_qry);
  		echo "We have " . $count ." Items!" . "<br/>";
 ?>
 <table class='table table-stripped'>
 <tr><th>Serial Number</th><th>Item Name</th><th>Category</th><th colspan=3></tr>
  	<?php 
  		if(isset($_GET['page'])){
  			$page=$_GET['page'];
  		}
  		else{
  		$page=1;
  		}
  		$start_from=($page-1)*4;
  		
  		$select_item=mysql_query("SELECT * FROM items limit $start_from,4");
  		
  		while($row_item=mysql_fetch_array($select_item)){
  			?>
  		<tr><td><?php echo $row_item['sn'];?></td><td><?php echo $row_item['name'];?></td><td><a href="../category.php?cat=<?php echo $row_item['category'];?>" target='_blank'><?php echo $row_item['category'];?></a></a></td>
  		<script type="text/javascript">
  		$(document).on("click", ".open-AddBookDialog", function () {
  		     var myBookId = $(this).data('id');
  		     $(".modal-body #bookId").val( myBookId );
  		});
  		</script>
  		<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Delete Item</h4>
      </div>
      <div class="modal-body">
       
        Do you Really Wants to Delete this Item?
        <form action="delete.php" method="post">
        <input type="hidden" name="bookId" id="bookId" value=""/>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
        <button type="submit" class="btn btn-primary">Yes</button>
        </form>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


  		<td><a href="../details.php?id=<?php echo $row_item['id'];?>" target='_blank' rel="tooltip" title="Details are here, click it!"><i class="fa fa-eye"></i></a></td>
  		
  		<td><a href="edit.php?id=<?php echo $row_item['id'];?>" target='_blank' rel="tooltip" title="Edit here!"><i class="fa fa-pencil"></i></a></td>
  		<td><a href="javascript:void" target='_blank' rel="tooltip" title="Delete here!" data-toggle="modal" data-target="#myModal" class='open-AddBookDialog' data-id="<?php echo $row_item['id'];?>"><i class="fa fa-trash-o"></i></a></td>
  		
  		
  		<td></td><td></td></tr>
  		
  		<?php 	
  		}
  	
  	?>
  </table>
  <?php 
  	$total_pages=ceil($count/4);
  	echo "<ul class='pagination'>";
  	for($i=1;$i<=$total_pages;$i++){
  		if($i==$page){
  			echo "<li class='active'><a href='javascript:void'>$i</a></li>";
  		}
  		else{
  		echo "<li><a href='default.php?page=$i'>$i</a></li>";
  		}
  		
  	}
  	echo "</ul>";
  
  ?>
  </div>
  <div class="tab-pane" id="messages">Pricing</div>
  <div class="tab-pane" id="settings">Customer Management</div>
</div>

<script>
  $(function () {
	  $('#myTab a').click(function (e) {
		  e.preventDefault();
		  $(this).tab('show');
		});
  });
</script>
      </div>

      <hr>

      <footer>
        <p>&copy; Company 2013</p>
      </footer>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
   
  </body>
</html>
